package com.example.androidlearning2200;

import android.content.Intent;
import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.androidlearning2200.adapter.AppAdapter;
import com.example.androidlearning2200.bean.AppBean;

import java.util.ArrayList;
import java.util.List;

public class AppRecentActivity extends BaseActivity {

    private List<AppBean> datas = new ArrayList<>();
    private RecyclerView rvAppEntry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_recent);
        // 准备测试数据
        datas.add(new AppBean(R.mipmap.ic_calculator, "计算器"));
        datas.add(new AppBean(R.mipmap.ic_camera, "相机"));
        datas.add(new AppBean(R.mipmap.ic_chrome, "浏览器"));
        datas.add(new AppBean(R.mipmap.ic_clock, "闹钟"));
        datas.add(new AppBean(R.mipmap.ic_comic, "漫画"));
        datas.add(new AppBean(R.mipmap.ic_download, "下载"));
        datas.add(new AppBean(R.mipmap.ic_email, "邮箱"));
        datas.add(new AppBean(R.mipmap.ic_gps, "导航"));
        datas.add(new AppBean(R.mipmap.ic_music, "音乐"));
        datas.add(new AppBean(R.mipmap.ic_news, "新闻"));
        datas.add(new AppBean(R.mipmap.ic_note, "记事本"));
        datas.add(new AppBean(R.mipmap.ic_picture, "图库"));
        datas.add(new AppBean(R.mipmap.ic_pinyin, "输入法"));
        datas.add(new AppBean(R.mipmap.ic_settings, "设置"));
        datas.add(new AppBean(R.mipmap.ic_shopping, "商城"));
        datas.add(new AppBean(R.mipmap.ic_sms, "短信"));
        datas.add(new AppBean(R.mipmap.ic_translation, "翻译"));
        datas.add(new AppBean(R.mipmap.ic_video, "视频"));
        // 找到RecyclerView控件
        rvAppEntry = findViewById(R.id.rvAppEntry);
        rvAppEntry.setLayoutManager(new GridLayoutManager(this, 4));
        rvAppEntry.setAdapter(new AppAdapter(datas.subList(0, 8)));
        // 点击更多，跳转至全部应用界面
        findViewById(R.id.tvMore).setOnClickListener(v -> startActivity(new Intent(AppRecentActivity.this, AppAllActivity.class)));
    }

}